package com.zmzncs.lmtc.module.promotion.pojo.duration_rule;

import com.zmzncs.lmtc.common.util.ExceptionUtil;
import com.zmzncs.lmtc.module.promotion.pojo.duration_rule_fee_scale.DurationRuleFeeScaleForm;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 促销-时长规则类型
 * </p>
 *
 * @author 任建波
 * @since 2020-08-12
 */
@Data
public class DurationRuleAddForm implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "规则名称", required = true)
    @NotBlank
    private String ruleName;

    @ApiModelProperty(value = "描述备注")
    private String remark;

    @ApiModelProperty(value = "停车场id集合")
    private List<String> parkIds;

    @ApiModelProperty(value = "月租类型集合")
    @Size(min = 1)
    List<DurationRuleFeeScaleForm> monthRentTypes;

    @ApiModelProperty(value = "是否所有停车场（1：是，0否）", required = true)
    @NotNull
    private Integer ifAllParks;

    /**
     * 表单验证
     */
    public void validate(){
        //  当选择部分停车场时，parkIds不能为空
        if(ifAllParks.equals(0)){
            if(parkIds.size() == 0){
                ExceptionUtil.paramException("当ifAllParks为0时，parkIds不能为空");
            }
        }
        //  校验ifAllParks
        if(!(ifAllParks.equals(0) || ifAllParks.equals(1))){
            ExceptionUtil.paramException("ifAllParks取值范围（1：是，0否）");
        }
    }

}
